import React from "react";
import axios from 'axios'

const Index = () => {

  const handleSubmit = (e) => {
    e.preventDefault();
    const form = e.target;

    const title = form.title.value
    const type = form.type.value
    const price = form.price.value
    const typeName = form.typeName.value
    const data = {
      title, type, price, typeName, id: new Date().getTime()
    }
    axios.post('/api/list/add', data).then((resp) => {
      alert(resp.data.message)
    })
  };
  return (
    <div>
      <form onSubmit={handleSubmit}>
        <div>
          <label htmlFor="">标题</label>
          <input type="text" name="title" />
        </div>
        <div>
          <label htmlFor="">价格</label>
          <input type="text" name="price" />
        </div>
        <div>
          <label htmlFor="">类型</label>
          <input type="text" name="type" />
        </div>
        <div>
          <label htmlFor="">支付类型</label>
          <input type="text" name="typeName" />
        </div>
        <button>提交</button>
      </form>
    </div>
  );
};

export default Index;
